package com.example.smartcity_40.lawyer.apter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.smartcity_40.R;
import com.example.smartcity_40.lawyer.LawyerdetailsActivity;
import com.example.smartcity_40.lawyer.SeekDetailsActivity;
import com.example.smartcity_40.lawyer.bean.UserSeekBean;
import com.example.smartcity_40.tool.Tool;
import com.google.gson.Gson;

import java.util.List;

public class UserSeekAdapter extends  RecyclerView.Adapter<UserSeekAdapter.Myhot> {

    private Context context;
    private List<UserSeekBean.RowsBean> list;

    public UserSeekAdapter(Context context) {
        this.context = context;
    }

    public void setDate(List<UserSeekBean.RowsBean> list){
        this.list = list;
    }
    @NonNull
    @Override
    public UserSeekAdapter.Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.l_item_userseek, null);
        return new UserSeekAdapter.Myhot(inflate);

    }

    @Override
    public void onBindViewHolder(@NonNull UserSeekAdapter.Myhot holder, int position) {
        try {
            String imgUrl = list.get(position).getImageUrls();

                Glide.with(context).load(Tool.url+imgUrl)
                        .error(R.drawable.waimai)
                        .into(holder.imageUrls);

            String serviceName = list.get(position).getLawyerName();
            if(!TextUtils.isEmpty(serviceName)){
                holder.lawyerName.setText(serviceName);
            }

            String state = list.get(position).getState();
            if("0".equals(state)){
                holder.state.setText("状态: 未处理");
            }else if("1".equals(state)){
                holder.state.setText("状态: 已处理");
            }


            String workStartAt = list.get(position).getLegalExpertiseName();
            if(!TextUtils.isEmpty(workStartAt)){
                holder.legalExpertiseName.setText(workStartAt);
            }


            String legalExpertiseName = list.get(position).getCreateTime();
            if(!TextUtils.isEmpty(legalExpertiseName)){
                holder.createTime.setText(legalExpertiseName);
            }

            holder.relayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, SeekDetailsActivity.class);
                    Gson gson = new Gson();
                    String bean = gson.toJson(list.get(position));
                    intent.putExtra("seekdetails",bean);
                    context.startActivity(intent);
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }
/*
*
*  <!-- 律师头像、名称、从业年限、咨询人数、
    法律专长、好评率和咨询按钮-->
*
* */

    class Myhot extends RecyclerView.ViewHolder{

        private final TextView lawyerName;
        private final TextView legalExpertiseName;
        private final TextView state;
        private final TextView createTime;
        private final ImageView imageUrls;
        private final RelativeLayout relayout;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            imageUrls = itemView.findViewById(R.id.imageUrls);
            lawyerName = itemView.findViewById(R.id.lawyerName);
            legalExpertiseName = itemView.findViewById(R.id.legalExpertiseName);
            state = itemView.findViewById(R.id.state);
            createTime = itemView.findViewById(R.id.createTime);
            relayout = itemView.findViewById(R.id.relayout);
        }
    }
}



